'use strict';
/**
 * @author 张少辉
 * 创建时间： 2015-11-20 10:25:00
 * 创建任务号：无
 * 创建原因：拦截请求，添加token
 */
angular.module('nec-admin.common')
    .factory('httpRequestInterceptor', ['$q', '$injector',
        function($q, $injector) {
            return {
                request: function(config) {
                    var tokenService = $injector.get('tokenService');
                    if (tokenService.getToken()) {
                        config.headers = config.headers || {};
                        if(!config.headers.Authorization) {
                            config.headers.Authorization = tokenService.getToken();
                        }
                    }
                    return config || $q.when(config);
                }

                // requestError: function(rejection) {
                //  console.log(rejection);
                //     return $q.reject(rejection);
                // },

                // response: function(response) {
                //  console.log(response);
                //     return response || $q.when(response);
                // }

                // responseError: function(rejection) {
                //  console.log(rejection);
                //     return $q.reject(rejection);
                // }
            };
        }
    ]);
